package me.json.other;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

public class City {

    private String id;

    private String areaId;

    private String areaName;

    private String parentId;

    public City() {
        super();
    }

    public City(String parentId, String areaName) {
        super();
        this.areaName = areaName;
        this.parentId = parentId;
    }

    public static City fromJsonParser(JsonParser jsonParser) throws JsonParseException, IOException {

        City city = null;

        if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {

            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {

                String fieldName = jsonParser.getCurrentName();

                if (fieldName == null) {
                    continue;
                }

                if (city == null) {
                    city = new City();
                }

                if ("id".equals(fieldName)) {
                    jsonParser.nextToken();
                    city.id = jsonParser.getText();
                    continue;
                }

                if ("areaId".equals(fieldName)) {
                    jsonParser.nextToken();
                    city.areaId = jsonParser.getText();
                    continue;
                }

                if ("areaName".equals(fieldName)) {
                    jsonParser.nextToken();
                    city.areaName = jsonParser.getText();
                    continue;
                }

                if ("parentId".equals(fieldName)) {
                    jsonParser.nextToken();
                    city.parentId = jsonParser.getText();
                    continue;
                }

                jsonParser.skipChildren();
            }
        }

        return city;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAreaId() {
        return areaId;
    }

    public void setAreaId(String areaId) {
        this.areaId = areaId;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    @Override
    public String toString() {
        return areaName;
    }
}
